<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

		<title>采购发票新增</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link rel="stylesheet" type="text/css" charset="UTF-8"
			href="<%=request.getContextPath()%>/css/public.css">
		<script language="JavaScript" charset="UTF-8"
			src="<%=request.getContextPath()%>/js/public.js"></script>
		<script language="JavaScript" charset="UTF-8"
			src="<%=request.getContextPath()%>/js/date1.js"></script>
		<script language="JavaScript" charset="UTF-8"
			src="<%=request.getContextPath()%>/js/stockInvoice.js"></script>
		<script language="JavaScript" charset="UTF-8"
			src="<%=request.getContextPath()%>/js/ajax.js"></script>
		<script language="JavaScript" charset="UTF-8"
			src="<%=request.getContextPath()%>/js/validate.js"></script>
		<script type="text/javascript">
			function trans() {
				var type = document.getElementById("type").value;
				if (type == 0) {
				alert("请输入原单类型");
			} else {
				if (type == 1) {
				window.location.href('stockInvoice!select.action');
			} else {
				window.location.href('stockInvoice!selectInStorage.action');
					}
				}
			}
		</script>
		<script type="text/javascript">
			function validate(){
				//发票日期
				var invoiceDate = document.getElementById('invoiceDate');
				//币别名称
				var currencyName = document.getElementById('currencyName');
				//供应商名称
				var supplierName = document.getElementById('supplierName');
				//发票号码
				var invoiceNo = document.getElementById('invoiceNo');
				//付款期限
				var payDate = document.getElementById('payDate');
				//表格
				var mbody = document.getElementById('mbody');
				//验证发票日期
				if(!isNotNull(invoiceDate,'发票日期'))
					return false;
				//验证币别名称
				if(!isNotNull(currencyName,'币别'))
					return false;
				//验证供应商名称
				if(!isNotNull(supplierName,'供应商'))
					return false ;	
				//验证发票号码
				if(!isNotNull(invoiceNo,'发票号码'))
					return false;
				//验证付款期限
				if(!isNotNull(payDate,'付款期限'))
					return false;
				if(mbody.rows.length<=0){
					alert("请添加明细");
					return false;			
				}
				else{
					for(var i=0;i<mbody.rows.length;i++){
						//代码
						var materialCode = document.getElementById('materialCode'+i);
						//计量单位
						var measureUnitName = document.getElementById('measureUnitName'+i);
						//数量
						var cost = document.getElementById('cost'+i);
						//单价
						var unitPrice = document.getElementById('unitPrice'+i);
						//含税单价
						var realTotalUnitPrice = document.getElementById('realTotalUnitPrice'+1);
						//金额
						var money = document.getElementById('money'+rowIndex);
						//折扣率
						var discount = document.getElementById('discount'+rowIndex);
						
						//折扣额
						var discountPrice = document.getElementById('discountPrice'+rowIndex);
						
						//税额
						var dutyPrice = document.getElementById('dutyPrice'+rowIndex);
						//税率
						var dutyFrank = document.getElementById('dutyFrank'+rowIndex);
						
						//价税合计
						var totalMoney = document.getElementById('totalMoney'+rowIndex);
						
						var rowIndex = i+1 ;
						//验证代码					
						if(!(isNotNull(materialCode,'第'+rowIndex+'行:'+'物料代码')&&f_check_ZhOrNumOrLett(materialCode,'第'+rowIndex+'行:'+'物料代码')))
							return false;
						//单位
						if(!(isNotNull(measureUnitName,'第'+rowIndex+'行:'+'单位')&&f_check_ZhOrNumOrLett(measureUnitName,'第'+rowIndex+'行:'+'单位')))
							return false;
						//数量
						if(!(isNotNull(cost,'第'+rowIndex+'行:'+'数量')&&f_check_float(cost,'第'+rowIndex+'行:'+'数量')))
							return false;
						//单价
						if(!(isNotNull(unitPrice,'第'+rowIndex+'行:'+'单价')&&f_check_float(unitPrice,'第'+rowIndex+'行:'+'单价')))
							return false;
						//含税单价
						if(!(isNotNull(realTotalUnitPrice,'第'+rowIndex+'行:'+'实际含税单价')&&f_check_float(realTotalUnitPrice,'第'+rowIndex+'行:'+'实际含税单价')))
							return false;
						//金额
						if(!(isNotNull(money,'第'+rowIndex+'行:'+'金额')&&f_check_float(money,'第'+rowIndex+'行:'+'金额')))
							return false;
						
						//折扣率		
						if(!(isNotNull(discount,'第'+rowIndex+'行:'+'折扣率')&&f_check_float(discount,'第'+rowIndex+'行:'+'折扣率')))
							return false;
						//折扣额	
						if(!(isNotNull(discountPrice,'第'+rowIndex+'行:'+'折扣额')&&f_check_float(discountPrice,'第'+rowIndex+'行:'+'折扣额')))
							return false;
						//税额	
						if(!(isNotNull(dutyPrice,'第'+rowIndex+'行:'+'税额')&&f_check_float(dutyPrice,'第'+rowIndex+'行:'+'税额')))
							return false;
						//稅率
						if(!(isNotNull(dutyFrank,'第'+rowIndex+'行:'+'稅率')&&f_check_float(dutyFrank,'第'+rowIndex+'行:'+'稅率')))
							return false;
							
					}				
				}
			}
		
		</script>		
		
	</head>
	<body>
	<div id="info_all">
		<div id="info_top">
			采购发票新增
		</div>
		<!-- 主输入区 -->
		<!-- 功能按钮 -->
		<s:form action="addStockInvoice.action" method="post" theme="simple"
				 id="delrow" onsubmit=" return validate()" cssStyle="margin-top:0px;">
		<div id="info_main">
			<!-- 查询栏 -->
			<div id="info_input">
				<hr>
				<table>
					<tr>
					<!-- 
						<td>
							发票类型
						</td>
						<td>
							<select name="stockInvoiceModel.billType" style="width: 107px;">
								<option value="1" selected>
									普通发票
								</option>
								<option value="2">
									专业发票
								</option>
							</select>
						</td>
					 -->
						<td width="60px">
							红蓝字
						</td>
						<td width="130px">
							<select name="stockInvoiceModel.tag" style="width: 107px;">
								<option value="1" selected>
									蓝字
								</option>
								<option value="2">
									红字
								</option>
							</select>
						</td>
					</tr>
					<tr>
						<td>
							源单类型
						</td>
						<td width="130px">
							<s:select list="#{'0':'','1':'采购订单','2':'采购入库'}" id="type"
								name="stockInvoiceModel.sourceBillType" cssStyle="width:107px;"></s:select>
						</td>
						<td>
							选单号
						</td>
						<td>
							<s:textfield name="formerBillNum" id="formerBillNum" size="12"
								readonly="true"></s:textfield>
							<a href="#" onclick="trans()" onfocus="this.blur()"> <img
									src="images/kookup.gif" /> </a>
						</td>

						<td width="50px">
							日期(*)
						</td>
						<td width="100px">
							<input name="stockInvoiceModel.invoiceDate" id="invoiceDate" size="12" value=''
								readonly='readonly' style='cursor: hand'
								onclick=calendar.setHook(this)>
						</td>
						<td width="50px">
							币别(*)
						</td>
						<td>
							<s:hidden id="currencyId" name="stockInvoiceModel.currencyId"></s:hidden>
							<s:textfield id="currencyName" size="12" readonly="true"></s:textfield>
							<a href="#"
								onclick="openWin('selectCurrency.action','moneykind',580,500,0);return false;"
								onfocus="this.blur()"><img src="images/kookup.gif">
							</a>
						</td>
						<td width="50px">
							汇率(*)
						</td>
						<td width="130px">
							<s:textfield id="rate" name="rate" readonly="true" size="12" ></s:textfield>
						</td>

					</tr>
					<tr>

						<td width="80px">
							<s:text name="供应商(*)"></s:text>
							<s:hidden id="hiddenStaffName"></s:hidden>
						</td>
						<td width="130px">
							<s:hidden id="supplierId" name="stockInvoiceModel.supplierId"></s:hidden>
							<s:textfield id="supplierName" size="12" readonly="true"></s:textfield>
							<a href="#"
								onclick="openWin('supplierSelectA.action','selectSupplier',800,600,0);return false;"
								onfocus="this.blur()"><img src="images/kookup.gif">
							</a>
						</td>
						<td>
							地址
						</td>
						<td>
							<s:textfield id="address" name="address" size="12" readonly="true"></s:textfield>
						</td>
						<td>
							开户银行
						</td>
						<td>
							<s:textfield id="openAccountBank" name="openAccountBank" size="12" readonly="true"></s:textfield>
						</td>
						<td>
							纳税登记号
						</td>
						<td>
							<s:textfield id="taxRegisterNo" name="taxRegisterNo" size="12" readonly="true"></s:textfield>
						</td>
						<td>
							发票号码(*)
						</td>
						<td width="100px">
							<s:textfield name="stockInvoiceModel.invoiceNo" size="12"
								id="invoiceNo"></s:textfield>
						</td>

					</tr>

					<tr>
						<td>
							采购方式(*)
						</td>
						<td width="108px">
							<select name="stockInvoiceModel.stockWay" style="width: 107px;">
								<option value="0" selected>
									现购
								</option>
								<option value="1">
									赊购
								</option>
							</select>
						</td>
						<td>
							付款期限
						</td>
						<td>
							<input name="stockInvoiceModel.payDate" size="12" value=''
								id='payDate' readonly='readonly' style='cursor: hand'
								onclick=calendar.setHook(this)>
						</td>
						<td>
							主管
						</td>
						<td>
							<s:hidden id="candiateId"></s:hidden>
							<s:hidden id="candiateName"></s:hidden>
							<s:hidden name="stockInvoiceModel.managerId" id="managerId"></s:hidden>
							<s:textfield name="" id="managerName" size="12" readonly="true"></s:textfield>
							<img src="images/kookup.gif" style="cursor:hand"  onclick="multiSelect2('candiateName','candiateId','managerName','managerId','selectMultiCandiate.action','candiate',700,800,0)">
						</td>

						<td>
							部门
						</td>
						<td>
							<s:hidden name="stockInvoiceModel.departmentId" id="departmentId"></s:hidden>
							<s:textfield name="" id="departmentName" size="12" readonly="true"></s:textfield>
							<img src="images/kookup.gif" style="cursor:hand"  onclick="openWin('selectDepartment.action','department',500,600,0)">
						</td>
						<td>
							业务员
						</td>
						<td>
							<s:hidden name="stockInvoiceModel.businessId" id="busnisserId"></s:hidden>
							<s:textfield name="" id="businesserName" size="12" readonly="true"></s:textfield>
							<img src="images/kookup.gif" style="cursor:hand"  onclick="multiSelect2('candiateName','candiateId','businesserName','busnisserId','selectMultiCandiate.action','candiate',500,600,0)">
						</td>
					</tr>
					<tr>

						<td>
							开票人
						</td>
						<td>
							<s:textfield name="stockInvoiceModel.ticketer" id="ticketerId"
								size="12"></s:textfield>
						</td>

						<td>
							摘要
						</td>
						<td colspan="3">
							<s:textfield name="stockInvoiceModel.remark" size="12"
								id="remark"></s:textfield>

						</td>

					</tr>
				</table>
				<hr>
			</div>
			<div class="sele" style="text-align: left; padding-left: 10px;">
				<input type="button" value="新增" onClick="addStockInvoiceRow()"
					onfocus="this.blur()" onMouseOver="this.className='btnover'"
					onmouseout="this.className='btnout'" class="btnsize" />
				<input type="button" value="删除" onClick="delrow()"
					onFocus="this.blur()" onMouseOver="this.className='btnover'"
					onmouseout="this.className='btnout'" class="btnsize" />
				<hr>
			</div>
			<!-- 信息显示栏 -->
			<div id="info_info4">
				<table id="info_table" width="2000px" cellspacing=1px
					cellpadding=1px class="sortable">
					<thead id="head">
						<tr>
							<th>
								<input type="checkbox" name="checkbox" onClick="selectAll()" />
							</th>
							<th width="80px">
								物料代码(*)
							</th>
							<th width="80px">
								物料名称
							</th>
							<th width="80px">
								规格型号
							</th>
							<th width="80px">
								辅助属性
							</th>
							<th width="80px">
								基本单位名称
							</th>
							<th width="80px">
								基本单位数量
							</th>
							<th width="80px">
								单位(*)
							</th>
							<th width="80px">
								数量
							</th>
							<th width="80px">
								单价
							</th>
							<th width="80px">
								折扣率(%)
							</th>
							<th width="80px">
								税率(%)
							</th>
							<th width="80px">
								含税单价
							</th>
							<th width="80px">
								实际含税单价
							</th>
							<th width="80px">
								金额
							</th>
							<th width="80px">
								金额（本位币）
							</th>
							<th width="80px">
								折扣额
							</th>
							<th width="80px">
								折扣额（本位币）
							</th>
							<th width="80px">
								税额
							</th>
							<th width="80px">
								税额（本位币）
							</th>
							<th width="80px">
								价税合计
							</th>
							<th width="80px">
								价税合计（本位币）
							</th>
							<th width="100px">
								订单含税单价
							</th>
							<th width="80px">
								备注
							</th>
							<th width="80px">
								源单单号
							</th>
							<th width="80px">
								订单单号
							</th>
						</tr>
					</thead>
					<tbody id="mbody">
					</tbody>
					<tfoot>
						<tr>
						</tr>
					</tfoot>
				</table>
				<script language="javascript">  
						//("表格名称","奇数行背景","偶数行背景","点击后背景");
						 mouseclick("info_table","#ffffff","#ffffff","#e6f0fd");
						 //("表格名称","奇数行背景","偶数行背景");
						 //setcolor("t","#ffffff","#ffffff");
				</script>
			</div>
			<div style="margin: 6px; text-align: center;">
				<input type="submit" value="保存"
					onFocus="this.blur()" onMouseOver="this.className='btnover'"
					onmouseout="this.className='btnout'" class="btnsize" />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="button" value="返回" onClick=""
				onFocus="this.blur()" onMouseOver="this.className='btnover'"
				onmouseout="this.className='btnout'" class="btnsize" />
			</div>
		</div>
		</s:form>
	</div>
	</body>
</html>
